#include "Operand.h"


Operand::Operand(std::string name, bool isConst, DataType dataType, unsigned int priority, Node * parent)
{
	this->_name = name;
	this->_isConst = isConst;
	this->_dataType = dataType;
	this->_priority = priority;
	this->_parent = parent;
}

Operand::Operand()
{
}

void Operand::print(std::string& tree)
{
	tree.append(this->_name);
}

void Operand::clone(Node** node)
{
	(*node) = new Operand(this->_name, this->_isConst, this->_dataType, this->_priority, this->_parent);
}

DataType Operand::getDataType() const
{
	return _dataType;
}

bool Operand::isConst() const
{
	return _isConst;
}

Operand::~Operand(void)
{
}

int Operand::getType() const
{
	return OPERAND;
}

bool Operand::checkNode(std::vector<Variables> & vars, const Node* goal)
{
	return false;
}


std::string Operand::getValue(std::vector<Variables> vars)
{
	if(this->isConst())
	{
		return this->getName();
	}
	else
	{
		for(int i=0;i<vars.size();i++)
		{
			if(vars[i].getName().compare(this->getName()) == 0)
			{
				return vars[i].getValue();
			}
		}
	}
}


void Operand::setValue(std::vector<Variables> & vars, std::string val)
{
	for(int i=0;i<vars.size();i++)
	{
		if(vars[i].getName().compare(this->getName()) == 0)
		{
			vars[i].setValue(val);
		}
	}
}